package com.mewp.permissions.system.execption;

import com.mewp.permissions.common.entity.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 自定义全局异常类
 *
 * @author mewp
 * @version 1.0
 * @date 2023/7/28 04:34
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class CustomerException extends RuntimeException {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 异常信息
     */
    private String message;

    /**
     * 通过状态码和错误消息创建异常对象
     *
     * @param code    状态码
     * @param message 错误信息
     */
    public CustomerException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 接收枚举类型对象
     *
     * @param resultCodeEnum 异常枚举
     */
    public CustomerException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.message = resultCodeEnum.getMessage();
    }
}
